package fr.umlv.m2.jee.pmlv.service.subject.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import fr.umlv.m2.jee.pmlv.persistence.subject.Comment;
import fr.umlv.m2.jee.pmlv.persistence.subject.dao.ICommentDAO;
import fr.umlv.m2.jee.pmlv.service.subject.DisplayComment;
import fr.umlv.m2.jee.pmlv.service.subject.IDisplayCommentService;
import org.springframework.transaction.annotation.Transactional;

@Service("defautDisplayCommentService")
public class DefautDisplayCommentService implements IDisplayCommentService {
	
	@Autowired
	@Qualifier("hibernateCommentDAO")
	private ICommentDAO dao;

	@Override
        @Transactional(readOnly=true)
	public List<DisplayComment> getAllDisplayComment() {
		 ArrayList< DisplayComment > result = new ArrayList< DisplayComment >(16);

	        System.err.println("\n\n ON ENTRE DANS LA FONCTION\n\n");
	        for(Comment comment : dao.findAll() ) {
	            result.add(new DisplayComment(comment));
	        }

	        return result;
	}

}
